//
//  WYLableView.m
//  微博oc
//
//  Created by 王玉东 on 16/4/8.
//  Copyright © 2016年 wyd. All rights reserved.
//

#import "WYLableView.h"

@interface WYLableView()
@property (weak, nonatomic) IBOutlet UITextField *searchText;
@property (weak, nonatomic) IBOutlet UIButton *cancleBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightConstraint;

@end

@implementation WYLableView


//-(instancetype)initWithFrame:(CGRect)frame{
//
//    if (self = [super initWithFrame:frame]) {
//    
//       
//        
//        
//    }
//    return self;
//}
#pragma mark - Xib设置属性
-(void)awakeFromNib{
    
    [super awakeFromNib];
    
 self.searchText.leftView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
    
    self.searchText.frame = CGRectMake(0, 0, 35,35);
    //设置leftView的图片的位置
    self.searchText.leftView.contentMode = UIViewContentModeCenter;
    //设置leftView的mode选择总是显示
    self.searchText.leftViewMode = UITextFieldViewModeAlways;
    
    self.searchText.layer.cornerRadius = 15;
    
    self.searchText.layer.masksToBounds = YES;
    
    self.searchText.layer.borderColor = [UIColor orangeColor].CGColor;
    
    self.searchText.layer.borderWidth = 2;
    

}



+(instancetype)getDiscover{

    WYLableView *discoverView = [[[NSBundle mainBundle]loadNibNamed:@"Lable" owner:nil options:nil]lastObject];
    
    return discoverView;
}
- (IBAction)textWillChange:(id)sender {
    
    self.rightConstraint.constant  = self.cancleBtn.frame.size.width;
    
    [UIView animateWithDuration:0.25 animations:^{
        
        [self layoutIfNeeded];
    }];
}

- (IBAction)cancleClick:(id)sender {
    
    self.rightConstraint.constant = 0;
    
    [self.searchText resignFirstResponder];
    
    [UIView animateWithDuration:0.25 animations:^{
        [self layoutIfNeeded];
    }];
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
